<script>
    import { goto } from '$app/navigation';
    import { page } from '$app/stores';
    import { acceptInvite } from '$lib/apiServer';

    $: inviteId = $page?.params?.invite;
    $: invite = $page.data;

    import LogIn from '$lib/components/LogIn.svelte';

    let disabled;
    let username;
    let password;

    async function onSubmit() {
        disabled = true;
        const response = await acceptInvite(inviteId, username, password);
        if (200 <= response.status && response.status < 300) {
            username = '';
            password = '';
            goto('/');
        }
        disabled = false;
    }
</script>

<p>Hi there! {invite.issuer.name} invites you to the conversation.</p>
<LogIn bind:disabled bind:username bind:password on:submit={onSubmit} />
